<?php

namespace app\common\utils;
use Intervention\Image\ImageManagerStatic;

class Image
{
    
    public static function merge($imagePath = "", $filename = '', $arr = [])
    {
        $image = ImageManagerStatic::make($imagePath);
        $path = public_path() . '/upload/';
        $fontSrc = $path . 'default/font.ttf';
        if (!empty($arr['text'])) {
            foreach ($arr['text'] as $key => $value) {
                $image->text($value[0], $value[1], $value[2], function ($font) use ($fontSrc,$value) {
                    $font->file($fontSrc);
                    if(!empty($value[3])){
                        $font->size($value[3]);
                    }else{
                        $font->size(12);
                    }
                });
            }
        }
        $image->save($filename);
    }
    
}